package myself.register.daoImpl;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import myself.entity.TeacherInfoEntity;
import myself.register.dao.RegisterDao;

@Repository
public class RegisterDaoImpl implements RegisterDao {

	Logger log = LoggerFactory.getLogger(RegisterDaoImpl.class);
	@Resource
	private JdbcTemplate jdbcTemplate;

	public void insertToTeacher(TeacherInfoEntity teacherInfoEntity) {

		try {
			String sql = "insert into ksxt_teacher_info (teacher_code,teacher_password,teacher_name) values (?,?,?)";

			this.jdbcTemplate.update(sql,
					new Object[] { teacherInfoEntity.getTeacherCode(),
							teacherInfoEntity.getTeacherPassword(),
							teacherInfoEntity.getTeacherName() });
		} catch (Exception e) {
			log.error("插入数据库失败！",e);
			e.printStackTrace();
		}
	}

	public String qryMaxTeacherCode() {

		String sql = "select Max(teacher_code) from ksxt_teacher_info";

		return this.jdbcTemplate.queryForObject(sql, String.class);
	}

}
